package com.zhao.demo.unbound.demo04_transformation.sample01_rollagg


import com.zhao.demo.Raytek
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

/**
 * Description: 滚动聚合算子案例演示<br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/11/30 15:36
 *
 * @author 柒柒
 * @version : 1.0
 */

object RollingAggregationDemo {
  def main(args: Array[String]): Unit = {
    //需求:计算出迄今为止分别放在北京西站不同场所红外测温仪所测量到的最高温度值(分组->max)

    //1.环境准备
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    //2.读取数据,计算,显示
    import org.apache.flink.api.scala._
    env.readTextFile("a_input/raytek/raytek.log")
      .map(perInfo =>{
        val arr = perInfo.split(",")
        val id = arr(0).trim
        val temperature = arr(1).trim.toDouble
        val name = arr(2).trim
        val timestamp = arr(3).trim.toLong
        val location = arr(4).trim
        Raytek(id, temperature, name, timestamp, location)
      }).keyBy("id") //分组
      .max("temperature")  //求每组中最高的温度
      .print("迄今为止每组汇总最高的温度信息是->")

    //3.启动
    env.execute()
  }
}












